package com.ttbj.product.api.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ttbj.freight.component.OrderStateComponent;
import com.ttbj.freight.dao.FreightMapper;
import com.ttbj.product.api.FreightFacade;
import com.ttbj.product.bean.dto.FreightDto;
import com.ttbj.product.bean.dto.PageGlobal;

@Service("freightFacade")
public class FreightFacadeImpl implements FreightFacade {

	@Autowired
	FreightMapper freightMapper = null;

	@Autowired
	OrderStateComponent orderStateComponent = null;

	@Override
	public List<FreightDto> historyFreight(Long driverId, Boolean toCmple, Integer isDate) {
		FreightDto freight = null;
		if (null == toCmple) {
			freight = new FreightDto(driverId, null);
		} else {
			freight = new FreightDto(driverId, toCmple == true ? 0 : 1);
		}
		return freightMapper.historyFreight(freight);
	}

	@Override
	public FreightDto detailFreight(Long waybillId) {
		return freightMapper.detailFreight(waybillId);
	}

	@Override
	public void updateOrderStateByCache(Long orderId, Integer orderState) {
		orderStateComponent.updateOrderStateCacheAdd(orderId, orderState);
	}

	@Override
	public boolean matchStateFull(Long orderId, Integer orderState) {
		return orderStateComponent.matchStateFull(orderId, orderState);
	}

	@Override
	public List<FreightDto> freightList(Long driverId, Integer isMove, Integer isCompl, PageGlobal pageGlobal) {
		Page<FreightDto> page = PageHelper.startPage(pageGlobal.getPageNum(), pageGlobal.getPageSize());
		List<FreightDto> freightList = freightMapper.freightList(driverId, isMove, isCompl);
		PageInfo<FreightDto> pageInfo = new PageInfo<FreightDto>(freightList,pageGlobal.getPageSize());
		List<FreightDto> list = pageInfo.getList();
		return list;
	}

	 

}
